<template>
    <h2>登录页面</h2>
    <table border="1">
        <tr>
        <td>名称：</td>
        <td>
            <input type="text" v-model="name" placeholder="请输入名称"/>
        </td>
    </tr>
    <tr>
        <td>密码</td>
        <td>
            <input type="text" v-model="pwd" placeholder="请输入密码"/>
        </td>
    </tr>
    <tr>
        <input type="button" value="登录" @click="Login"/>
    </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import {useRoute,useRouter} from 'vue-router'
    const route=useRoute();
    const router=useRouter();

    const name=ref("");
    const pwd=ref("");

    const Login=()=>{
        axios.get("https://localhost:7272/api/User/Login",{
            params:{
                name:name.value,
                pwd:pwd.value
            }
        })
        .then(res=>{
            console.log()
            if(res.data==-1){
                alert('此用户不存在');
            }
            else if(res.data==-2){
                alert('登录失败，密码不正确');
            }
            else{
                alert('登录成功');
                router.push({
                    name:"AddRoomState"
                })
            }
        })
    }

</script>
